@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">

    <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-inline">
            <input type="text" id="user_id" autocomplete="off" placeholder="请输入用户ID" class="layui-input">
        </div>

        <button class="layui-btn" data-type="reload">搜索</button>

    </div>

    <div class="layui-form-item">

        {{--        <label class="layui-form-label">会员ID</label>--}}
        {{--        <div class="layui-input-inline">--}}
        {{--            <input type="text" id="user_id" autocomplete="off" placeholder="请输入会员ID" class="layui-input">--}}
        {{--        </div>--}}

        {{--    </div>--}}
    </div>

    <table class="layui-hide" id="think-table" lay-filter="think-table"></table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="recharge">充值</a>
        {{--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>--}}
    </script>

    <script>

        layui.use('table', function () {
            let table = layui.table;
            UI.getPageTable(table, "{{route('admin.users.oli_bills')}}", [
                {field: 'oli_bills_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
                , {field: 'title', title: '标题'}
                , {field: 'user_id', title: ' 用户ID'}
                , {field: 'nums', title: ' 数量'}
                , {field: 'balance', title: ' 剩余'}
                , {field: 'balance', title: ' 时间',templet:function (d){
                    return Utils.paraseTime(d['created_at'])
               }}
            ]);

            table.on('tool(think-table)', function (obj) {
                let data = obj.data;
                {{--if(obj.event === 'edit'){--}}
                    {{--    UI.openLayer("{{route('admin.olis.edit')}}?oli_id="+data['oli_id'],980);--}}
                    {{--}--}}
                    {{--else if(obj.event == 'del'){--}}
                    {{--    UI.delete(data['goods_id'],function(res){--}}
                    {{--        table.reload('think-table');--}}
                    {{--    },"{{route('admin.goods.del')}}");--}}
                    {{--}--}}

                if(obj.event === 'recharge') {
                    layer.prompt({formType:0,title:"充值",value:10000},
                        function(value, index){
                            HttpUtils.post('{{route('admin.users.recharge')}}',{
                                money:value,
                                user_id:data['user_id']
                            },function (res){
                                if(res['code'] != 200){
                                    Utils.errorToast(res['msg'])
                                    return;
                                }
                                layer.close(index)
                                layui.table.reload("think-table");
                            });
                        });
                }
            });
            let $ = layui.$, active = {
                reload:function (){
                    let user_id = $('#user_id');
                    //执行重载
                    table.reload('think-table', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            'user_id':user_id.val(),
                        }
                    });
                }
            };
            $('.layui-btn-container .layui-btn').on('click', function () {
                let type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            $('.search .layui-btn').on('click', function () {
                let type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        })


    </script>


@include('admin.layout.bone_footer')
